﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HG.INF.BizTalk.SolutionWizard
{
    public partial class FrmSolutionWizard : Form
    {

        public string IntegrationName { get; set; }
        public string IntegrationCode { get; set; }

        public FrmSolutionWizard()
        {
            InitializeComponent();
        }

        

        private void txtIntegrationCode_TextChanged(object sender, EventArgs e)
        {

            if (txtIntegrationCode.Text.Length >= 3)
            {
                txtIntegrationCode.Text = ReplaceInvalidChars(txtIntegrationCode.Text);
            }
            CheckInputParams();
        }

       

        private void txtIntegrationName_TextChanged(object sender, EventArgs e)
        {
            if (txtIntegrationName.Text.Length >= 3)
            {
                txtIntegrationName.Text = ReplaceInvalidChars(txtIntegrationName.Text);
            }
            CheckInputParams();
        }

        #region Privates

        private string ReplaceInvalidChars(string p)
        {

            //get invalid chars for in path
            char[] invalidFileChars = Path.GetInvalidFileNameChars();

            //replace items with a '-' sign
            Array.ForEach(invalidFileChars, c => p = p.Replace(c.ToString(), "-"));
            p = p.Replace(" ", "");
            return p;
        }


        /// <summary>
        /// Integratie code dient langer te zijn dan 3 characters;
        /// </summary>
        private void CheckInputParams()
        {

            btnCreateSolution.Enabled = (txtIntegrationCode.Text.Length > 3 && txtIntegrationName.Text.Length > 4);

        } 
        #endregion

        private void btnCreateSolution_Click(object sender, EventArgs e)
        {
            IntegrationName = txtIntegrationName.Text.Trim();
            IntegrationCode = txtIntegrationCode.Text.Trim();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void FrmSolutionWizard_Load(object sender, EventArgs e)
        {
            txtIntegrationName.Text = IntegrationName;
        }
    }
}
